package com.profgj.profgj.utils;

import com.profgj.profgj.vo.ResultMsg;
import com.profgj.profgj.vo.ReturnResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.List;

/**
 * 对结果内容进行封装类
 */
public class ReturnOperator {

    /**
     * 结果内容处理方法
     * @param message   成功返回的描述信息
     * @param errorMsg  异常返回的描述信息
     * @param statusCode    据成功与失败的状态码 200成功/400失败
     * @param list  列表数据的返回对象 如果为空返回空数组
     * @param objec 单个对象返回的信息
     * @param httpStatus    HttpStatus中的枚举类型数据
     * @return
     */
    public static ResponseEntity<ResultMsg> createResultMsg(String message, String errorMsg, Integer statusCode, List list, Object objec, HttpStatus httpStatus){

        // 创建结果数据对象
        ResultMsg resultMsg = new ResultMsg();
        resultMsg.setMessage(message);
        resultMsg.setErrorMsg(errorMsg);
        resultMsg.setStatusCode(statusCode);
        resultMsg.setList(list);
        resultMsg.setObject(objec);
        // 返回http相应结果
        return new ResponseEntity<ResultMsg>(resultMsg,httpStatus);
    }

    public static ResponseEntity<ReturnResult> createResultMsg(Integer draw, Integer recordsTotal, Integer recordsFiltered, List list,HttpStatus httpStatus){

        // 创建结果数据对象
        ReturnResult returnResult = new ReturnResult();
        returnResult.setDraw(draw);
        returnResult.setRecordsFiltered(recordsFiltered);
        returnResult.setRecordsTotal(recordsTotal);
        returnResult.setData(list);
        // 返回http相应结果
        return new ResponseEntity<ReturnResult>(returnResult,httpStatus);
    }


    /**
     * 返回结果对象
     * @param message   成功信息
     * @param errorMsg  失败信息
     * @param statusCode    成功/失败 码
     * @param list          有列表数据通过此返回
     * @param object        有对象数据通过此返回
     * @return
     */
    public static ResultMsg createResult(String message, String errorMsg, Integer statusCode, List list, Object object){

        // 创建结果数据对象
        ResultMsg resultMsg = new ResultMsg();
        resultMsg.setMessage(message);
        resultMsg.setMessage(errorMsg);
        resultMsg.setStatusCode(statusCode);
        resultMsg.setList(list);
        resultMsg.setObject(object);
        return resultMsg;
    }
}
